package editor.osx;

import adventure.commands.skills.Skill;
import adventure.commands.skills.SkillEdit;
import adventure.commands.skills.SkillManager;
import adventure.placeable.PlaceableManager;
import adventure.placeable.PlaceableManagerEdit;
import adventure.vocation.Vocation;
import adventure.vocation.VocationEdit;
import adventure.vocation.VocationManager;
import java.text.NumberFormat;

/**
 *
 * @author Michael Hanns
 *
 */
public class EditorVocationView extends javax.swing.JDialog {

    private static final long serialVersionUID = -1522782237246166517L;
    private VocationManager vocations;
    private PlaceableManager placeables;
    private SkillManager skills;
    private int totalVocations;
    private WITNAFrameView parent;

    /**
     * Creates new form EditorItemView
     */
    public EditorVocationView(java.awt.Frame parent,
            VocationManager v, PlaceableManager p, SkillManager s) {
        super(parent, true);
        this.parent = (WITNAFrameView) parent;
        vocations = v;
        skills = s;
        placeables = p;
        initComponents();
        if (vocations.getVocation(1).getID() == 0) {
            vocations.newVocation();
        }
        fillTable();
        getVocationData(totalVocations - 1);
    }

    public void fillTable() {
        vocationListTable.removeAll();

        int x = 1;
        while (vocations.getVocation(x).getID() != 0) {
            vocationListTable.getModel().setValueAt(vocations.getVocation(x).getID(), x - 1, 0);
            vocationListTable.getModel().setValueAt(vocations.getVocation(x).getName(), x - 1, 1);
            x++;
        }

        totalVocations = x;

        vocationListTable.changeSelection(x - 1, 2, false, false);
    }

    public void getVocationData(int row) {
        if (row > 0) {
            final Vocation voc = vocations.getVocation(row);
            idBox.setText(voc.getID() + "");
            nameBox.setText(voc.getName());
            descriptionBox.setText(voc.getDescription());

            baseAtkField.setText(voc.getBaseAttack() + "");
            baseDefField.setText(voc.getBaseDefence() + "");
            baseIntField.setText(voc.getBaseIntel() + "");
            baseSpdField.setText(voc.getBaseSpeed() + "");
            baseLckField.setText(voc.getBaseLuck() + "");

            incAtkField.setText((int) (voc.getChanceAttack() * 100) + "");
            incDefField.setText((int) (voc.getChanceDefence() * 100) + "");
            incIntField.setText((int) (voc.getChanceIntel() * 100) + "");
            incSpdField.setText((int) (voc.getChanceSpeed() * 100) + "");
            incLckField.setText((int) (voc.getChanceLuck() * 100) + "");


            skillsList.setModel(new javax.swing.AbstractListModel() {
                Skill[] skills = ((VocationEdit) voc).getSkills();

                @Override
                public int getSize() {
                    return skills.length;
                }

                @Override
                public Object getElementAt(int i) {
                    return ((SkillEdit) skills[i]).getName() + " / Level "
                            + ((SkillEdit) skills[i]).levelLearned() + " "
                            + ((SkillEdit) skills[i]).getType();
                }
            });
        }
    }

    private void newVocation() {
        if (totalVocations <= 200) {
            if (vocations.getVocation(totalVocations - 1).getName().trim().length() == 0) {
                parent.printToConsole("You must specify a name for all existing vocations before creating a new one!");
            } else {
                vocations.newVocation();
                fillTable();
                getVocationData(totalVocations - 1);
            }
        } else {
            parent.printToConsole("You have reached the maximum number of vocations!");
        }
    }


    private void duplicateVocation(int id) {
        if (totalVocations <= 200) {
            if (vocations.getVocation(totalVocations - 1).getName().trim().length() == 0) {
                parent.printToConsole("You must specify a name for all existing vocations before duplicating one!");
            } else {
                if (id > 0) {
                    if (vocations.getVocation(id).getID() != 0) {
                        VocationEdit newVocation = (VocationEdit) vocations.getVocation(id).cloneThis();
                        newVocation.setID(totalVocations);
                        vocations.newVocation(newVocation);
                        fillTable();
                        getVocationData(totalVocations - 1);
                    } else {
                        parent.printToConsole("You must select an existing vocation before attempting to duplicate!");
                    }
                }
            }
        } else {
            parent.printToConsole("You have reached the maximum number of vocations!");
        }
    }

    private void addSkill(int id) {
        new DialogAddSkillView(parent, this,
                skills, (PlaceableManagerEdit) placeables, vocations.getVocation(id)).setVisible(true);
    }

    private void removeSkill(int id, int selectedSkill) {
        if (selectedSkill > -1) {
            vocations.removeSkill(id, selectedSkill);
            parent.printToConsole("Skill " + skillsList.getSelectedValue().toString() + " removed from "
                    + nameBox.getText() + ".");
            getVocationData(id);
        } else {
            parent.printToConsole("You must select a skill to remove from " + nameBox.getText() + " first!");
        }
    }

    private void applyChanges(int id, String name) {
        if (id > 0 && name.length() > 0) {

            String desc = descriptionBox.getText();

            ((VocationEdit) vocations.getVocation(id)).setName(name);
            ((VocationEdit) vocations.getVocation(id)).setDescription(desc);

            int val = parseInt(baseAtkField.getText());
            ((VocationEdit) vocations.getVocation(id)).setBaseAttack(val);
            val = parseInt(baseDefField.getText());
            ((VocationEdit) vocations.getVocation(id)).setBaseDefence(val);
            val = parseInt(baseIntField.getText());
            ((VocationEdit) vocations.getVocation(id)).setBaseIntel(val);
            val = parseInt(baseSpdField.getText());
            ((VocationEdit) vocations.getVocation(id)).setBaseSpeed(val);
            val = parseInt(baseLckField.getText());
            ((VocationEdit) vocations.getVocation(id)).setBaseLuck(val);


            val = parseInt(incAtkField.getText());
            ((VocationEdit) vocations.getVocation(id)).setChanceIncAttack((double) val / 100);
            val = parseInt(incDefField.getText());
            ((VocationEdit) vocations.getVocation(id)).setChanceIncDefence((double) val / 100);
            val = parseInt(incIntField.getText());
            ((VocationEdit) vocations.getVocation(id)).setChanceIncIntel((double) val / 100);
            val = parseInt(incSpdField.getText());
            ((VocationEdit) vocations.getVocation(id)).setChanceIncSpeed((double) val / 100);
            val = parseInt(incLckField.getText());
            ((VocationEdit) vocations.getVocation(id)).setChanceIncLuck((double) val / 100);

            fillTable();
            parent.setUnsavedChanges(true);

            parent.printToConsole("Vocation " + name + " updated.");
            getVocationData(id);
        } else {
            parent.printToConsole("WARNING: Vocation changes not saved. You must specify a name for the vocation!");
        }
    }

    private int parseInt(String text) {
        try {
            int i = Integer.parseInt(text);
            return i;
        } catch (NumberFormatException e) {
            return 0;
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane2 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList();
        itemListPane = new javax.swing.JScrollPane();
        vocationListTable = new javax.swing.JTable();
        nameBox = new javax.swing.JFormattedTextField();
        idBox = new javax.swing.JFormattedTextField(NumberFormat.getInstance());
        jScrollPane1 = new javax.swing.JScrollPane();
        descriptionBox = new javax.swing.JTextPane();
        idLabel = new javax.swing.JLabel();
        nameLabel = new javax.swing.JLabel();
        descriptionLabel = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        closeButton = new javax.swing.JButton();
        newVocationButton = new javax.swing.JButton();
        applyButton = new javax.swing.JButton();
        baseAtkField = new javax.swing.JFormattedTextField();
        baseDefField = new javax.swing.JFormattedTextField();
        baseIntField = new javax.swing.JFormattedTextField();
        baseSpdField = new javax.swing.JFormattedTextField();
        baseLckField = new javax.swing.JFormattedTextField();
        incAtkField = new javax.swing.JFormattedTextField();
        incLckField = new javax.swing.JFormattedTextField();
        incDefField = new javax.swing.JFormattedTextField();
        incSpdField = new javax.swing.JFormattedTextField();
        incIntField = new javax.swing.JFormattedTextField();
        baseLabel = new javax.swing.JLabel();
        incLabel = new javax.swing.JLabel();
        atkLabel = new javax.swing.JLabel();
        defLabel = new javax.swing.JLabel();
        intLabel = new javax.swing.JLabel();
        spdLabel = new javax.swing.JLabel();
        lckLabel = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        skillsList = new javax.swing.JList();
        skillsLabel = new javax.swing.JLabel();
        addSkillButton = new javax.swing.JButton();
        removeSkillButton = new javax.swing.JButton();
        duplicateButton = new javax.swing.JButton();

        jList1.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane2.setViewportView(jList1);

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Edit Vocations");
        setLocationByPlatform(true);
        setResizable(false);

        vocationListTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null}
            },
            new String [] {
                "#", "Name"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        vocationListTable.setToolTipText("Item list");
        vocationListTable.setColumnSelectionAllowed(true);
        vocationListTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        vocationListTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                vocationListTableMouseClicked(evt);
            }
        });
        itemListPane.setViewportView(vocationListTable);
        vocationListTable.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        vocationListTable.getColumnModel().getColumn(0).setMinWidth(10);
        vocationListTable.getColumnModel().getColumn(0).setPreferredWidth(25);
        vocationListTable.getColumnModel().getColumn(0).setMaxWidth(25);

        nameBox.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        nameBox.setToolTipText("Item name");

        idBox.setEditable(false);
        idBox.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        idBox.setToolTipText("Vocation number");

        descriptionBox.setToolTipText("Item description");
        jScrollPane1.setViewportView(descriptionBox);

        idLabel.setText("ID:");

        nameLabel.setText("Name:");

        descriptionLabel.setText("Description:");

        closeButton.setText("Close");
        closeButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                closeButtonActionPerformed(evt);
            }
        });

        newVocationButton.setText("Add new..");
        newVocationButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                newVocationButtonActionPerformed(evt);
            }
        });

        applyButton.setText("Apply");
        applyButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                applyButtonActionPerformed(evt);
            }
        });

        baseAtkField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0"))));
        baseAtkField.setText("55");
        baseAtkField.setHighlighter(null);
        baseAtkField.setMaximumSize(new java.awt.Dimension(14, 22));
        baseAtkField.setMinimumSize(new java.awt.Dimension(14, 22));
        baseAtkField.setPreferredSize(new java.awt.Dimension(14, 22));

        baseDefField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0"))));
        baseDefField.setText("55");
        baseDefField.setHighlighter(null);
        baseDefField.setMaximumSize(new java.awt.Dimension(14, 22));
        baseDefField.setMinimumSize(new java.awt.Dimension(14, 22));
        baseDefField.setPreferredSize(new java.awt.Dimension(14, 22));

        baseIntField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0"))));
        baseIntField.setText("55");
        baseIntField.setHighlighter(null);
        baseIntField.setMaximumSize(new java.awt.Dimension(14, 22));
        baseIntField.setMinimumSize(new java.awt.Dimension(14, 22));
        baseIntField.setPreferredSize(new java.awt.Dimension(14, 22));

        baseSpdField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0"))));
        baseSpdField.setText("55");
        baseSpdField.setHighlighter(null);
        baseSpdField.setMaximumSize(new java.awt.Dimension(14, 22));
        baseSpdField.setMinimumSize(new java.awt.Dimension(14, 22));
        baseSpdField.setPreferredSize(new java.awt.Dimension(14, 22));

        baseLckField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0"))));
        baseLckField.setText("55");
        baseLckField.setHighlighter(null);
        baseLckField.setMaximumSize(new java.awt.Dimension(14, 22));
        baseLckField.setMinimumSize(new java.awt.Dimension(14, 22));
        baseLckField.setPreferredSize(new java.awt.Dimension(14, 22));

        incAtkField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0"))));
        incAtkField.setText("55");
        incAtkField.setHighlighter(null);
        incAtkField.setMaximumSize(new java.awt.Dimension(14, 22));
        incAtkField.setMinimumSize(new java.awt.Dimension(14, 22));
        incAtkField.setPreferredSize(new java.awt.Dimension(14, 22));

        incLckField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0"))));
        incLckField.setText("55");
        incLckField.setHighlighter(null);
        incLckField.setMaximumSize(new java.awt.Dimension(14, 22));
        incLckField.setMinimumSize(new java.awt.Dimension(14, 22));
        incLckField.setPreferredSize(new java.awt.Dimension(14, 22));

        incDefField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0"))));
        incDefField.setText("55");
        incDefField.setHighlighter(null);
        incDefField.setMaximumSize(new java.awt.Dimension(14, 22));
        incDefField.setMinimumSize(new java.awt.Dimension(14, 22));
        incDefField.setPreferredSize(new java.awt.Dimension(14, 22));

        incSpdField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0"))));
        incSpdField.setText("55");
        incSpdField.setHighlighter(null);
        incSpdField.setMaximumSize(new java.awt.Dimension(14, 22));
        incSpdField.setMinimumSize(new java.awt.Dimension(14, 22));
        incSpdField.setPreferredSize(new java.awt.Dimension(14, 22));

        incIntField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0"))));
        incIntField.setText("55");
        incIntField.setHighlighter(null);
        incIntField.setMaximumSize(new java.awt.Dimension(14, 22));
        incIntField.setMinimumSize(new java.awt.Dimension(14, 22));
        incIntField.setPreferredSize(new java.awt.Dimension(14, 22));

        baseLabel.setText("Base stats:");

        incLabel.setText("Inc Chance:");

        atkLabel.setText(" Atk");

        defLabel.setText(" Def");

        intLabel.setText("  Int");

        spdLabel.setText(" Spd");

        lckLabel.setText(" Lck");

        jScrollPane3.setViewportView(skillsList);

        skillsLabel.setText("Skills:");

        addSkillButton.setText("Add");
        addSkillButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addSkillButtonActionPerformed(evt);
            }
        });

        removeSkillButton.setText("Remove");
        removeSkillButton.setMargin(new java.awt.Insets(2, 8, 2, 8));
        removeSkillButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removeSkillButtonActionPerformed(evt);
            }
        });

        duplicateButton.setText("Duplicate");
        duplicateButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                duplicateButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(itemListPane, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(newVocationButton)
                        .addGap(0, 0, 0)
                        .addComponent(duplicateButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(closeButton)
                        .addGap(0, 0, 0)
                        .addComponent(applyButton))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(idLabel)
                            .addComponent(idBox, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(nameLabel)
                                .addGap(0, 0, Short.MAX_VALUE))
                            .addComponent(nameBox)))
                    .addComponent(jScrollPane1)
                    .addComponent(jSeparator1)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(12, 12, 12)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(incLabel)
                                            .addComponent(baseLabel, javax.swing.GroupLayout.Alignment.TRAILING)))
                                    .addComponent(skillsLabel, javax.swing.GroupLayout.Alignment.TRAILING))
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(12, 12, 12)
                                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 248, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(removeSkillButton, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(addSkillButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(9, 9, 9)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                            .addComponent(incAtkField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addComponent(baseAtkField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 32, Short.MAX_VALUE)
                                            .addComponent(atkLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                                .addComponent(incDefField, javax.swing.GroupLayout.DEFAULT_SIZE, 30, Short.MAX_VALUE)
                                                .addComponent(baseDefField, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                            .addComponent(defLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGap(12, 12, 12)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(intLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addComponent(baseIntField, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addComponent(incIntField, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(spdLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addComponent(incSpdField, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addComponent(baseSpdField, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(lckLabel)
                                            .addComponent(baseLckField, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addComponent(incLckField, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                            .addComponent(descriptionLabel))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(itemListPane)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(nameLabel)
                            .addComponent(idLabel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(nameBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(idBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(descriptionLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(atkLabel)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(baseAtkField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(baseLabel))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(incAtkField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(incLabel)))
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(baseDefField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(incDefField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(layout.createSequentialGroup()
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(intLabel)
                                        .addComponent(defLabel))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(baseIntField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(incIntField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(spdLabel)
                                    .addGap(56, 56, 56))
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(baseSpdField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(incSpdField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(lckLabel)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(baseLckField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(incLckField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(skillsLabel)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(addSkillButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(removeSkillButton))
                            .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(30, 30, 30)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(newVocationButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(duplicateButton)
                            .addComponent(closeButton)
                            .addComponent(applyButton))))
                .addGap(12, 12, 12))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void vocationListTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_vocationListTableMouseClicked
        int row = vocationListTable.getSelectedRow();

        if (vocationListTable.getModel().getValueAt(row, 0) != null) {
            int id = Integer.parseInt(vocationListTable.getModel().getValueAt(row, 0).toString());
            getVocationData(id);
        }
    }//GEN-LAST:event_vocationListTableMouseClicked

    private void closeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeButtonActionPerformed
        dispose();
    }//GEN-LAST:event_closeButtonActionPerformed

    private void newVocationButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newVocationButtonActionPerformed
        newVocation();
    }//GEN-LAST:event_newVocationButtonActionPerformed

    private void applyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_applyButtonActionPerformed
        int id = Integer.parseInt(idBox.getText());
        String name = nameBox.getText();

        applyChanges(id, name);
    }//GEN-LAST:event_applyButtonActionPerformed

    private void addSkillButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addSkillButtonActionPerformed
        if(skills.totalSkills() == 0) {
            parent.printToConsole("You must create at least one Skill before attempting to add one to a vocation!");
        } else {
            int id = parseInt(idBox.getText());
            addSkill(id);
        }
    }//GEN-LAST:event_addSkillButtonActionPerformed
    private void removeSkillButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeSkillButtonActionPerformed
        int id = parseInt(idBox.getText());
        int selectedSkill = skillsList.getSelectedIndex();

        removeSkill(id, selectedSkill);
    }//GEN-LAST:event_removeSkillButtonActionPerformed

    private void duplicateButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_duplicateButtonActionPerformed
        int id = parseInt(idBox.getText());

        duplicateVocation(id);
    }//GEN-LAST:event_duplicateButtonActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addSkillButton;
    private javax.swing.JButton applyButton;
    private javax.swing.JLabel atkLabel;
    private javax.swing.JFormattedTextField baseAtkField;
    private javax.swing.JFormattedTextField baseDefField;
    private javax.swing.JFormattedTextField baseIntField;
    private javax.swing.JLabel baseLabel;
    private javax.swing.JFormattedTextField baseLckField;
    private javax.swing.JFormattedTextField baseSpdField;
    private javax.swing.JButton closeButton;
    private javax.swing.JLabel defLabel;
    private javax.swing.JTextPane descriptionBox;
    private javax.swing.JLabel descriptionLabel;
    private javax.swing.JButton duplicateButton;
    private javax.swing.JFormattedTextField idBox;
    private javax.swing.JLabel idLabel;
    private javax.swing.JFormattedTextField incAtkField;
    private javax.swing.JFormattedTextField incDefField;
    private javax.swing.JFormattedTextField incIntField;
    private javax.swing.JLabel incLabel;
    private javax.swing.JFormattedTextField incLckField;
    private javax.swing.JFormattedTextField incSpdField;
    private javax.swing.JLabel intLabel;
    private javax.swing.JScrollPane itemListPane;
    private javax.swing.JList jList1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JLabel lckLabel;
    private javax.swing.JFormattedTextField nameBox;
    private javax.swing.JLabel nameLabel;
    private javax.swing.JButton newVocationButton;
    private javax.swing.JButton removeSkillButton;
    private javax.swing.JLabel skillsLabel;
    private javax.swing.JList skillsList;
    private javax.swing.JLabel spdLabel;
    private javax.swing.JTable vocationListTable;
    // End of variables declaration//GEN-END:variables
}
